home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic 5 Developer's Kit / vb5 dev kit.iso / dev / tcp4w20 / samples / c / mini_ftp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-10  |  2.2 KB  |  81 lines

  1. /* *************************************************************** */
  2. /*      Mini - ftp                                                 */
  3. /* Sample app for Tcp4w.Dll: This program establishes a connection */
  4. /* waits for incoming frame then sends a QUIT command and exits    */
  5. /* *************************************************************** */
  6.  
  7. #define  STRICT +
  8. #include <windows.h>
  9. #include <string.h>
  10. #include <tcp4w.h>
  11.  
  12. #define MBox(sz)  MessageBox (NULL, sz, "Mini_ftp", MB_OK)
  13.  
  14.  
  15. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  16.                     LPSTR lpszCmdLine, int cmdShow)
  17. {
  18. int  Rc;
  19. char sz [256];
  20. char szTcp[128];
  21. SOCKET         ConnSock=INVALID_SOCKET;
  22.  
  23.     /* gets version of DLL */
  24.     Tcp4uVer (sz, sizeof sz);
  25.     MBox (sz);
  26.  
  27.     /* checks if first parameter OK */
  28.     if (lpszCmdLine==NULL  ||  lpszCmdLine[0]==0)
  29.       { 
  30.         MBox ("Usage: Mini_ftp <Host>");
  31.         return 0;
  32.       }
  33.     
  34.     
  35.     /* Inits winsocket use */
  36.     Rc= Tcp4uInit ();
  37.     if (Rc!=TCP4U_SUCCESS)  
  38.       { 
  39.         MBox ("Erreur in Init");
  40.         return 0;
  41.       }
  42.     
  43.     /* Establishes the connection */
  44.     Rc = TcpConnect (& ConnSock, lpszCmdLine, "ftp", NULL);
  45.     if (Rc!=TCP4U_SUCCESS)  
  46.       {
  47.         MBox (Tcp4uErrorString (Rc));
  48.         return 0;
  49.       }
  50.        
  51.     /* Waits 30sec for incoming message */
  52.     memset (szTcp, 0, sizeof szTcp);
  53.     Rc = TcpRecv (ConnSock, szTcp, sizeof szTcp - 1, 30, HFILE_ERROR);
  54.     /* if TcpRecv successful, Rc is the number of received bytes */
  55.     /* thus test if Rc below TCP4U_SUCCESS                       */
  56.     if (Rc<TCP4U_SUCCESS)
  57.       {
  58.          lstrcpy (sz, "Reception Error:\n");
  59.          lstrcat (sz, Tcp4uErrorString (Rc));
  60.       }
  61.     else
  62.       {
  63.          lstrcpy (sz, "Reception OK. Host answered:\n\n");
  64.          lstrcat (sz, szTcp);
  65.       }
  66.     
  67.     /* sends the Quit command with Telnet functions */
  68.     TnSend (ConnSock, "QUIT", FALSE, HFILE_ERROR);
  69.     
  70.     /* closes connection without waiting for server's answer */
  71.     TcpClose (&ConnSock);
  72.     
  73.     /* Releases Tcp4w resources */
  74.     Tcp4uCleanup ();
  75.  
  76.     /* Displays server message */
  77.     if (sz[0]!=0) MBox (sz);
  78.  
  79. return 0;
  80. } /* WinMain */
  81.